package ui;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class Message
{
	private static Message	instancs	= null;
	private FileHandler		handler		= null;
	private Logger			logger		= null;

	private Message()
	{
		try {
            handler = new FileHandler("test.log", true);
            handler.setFormatter(new SimpleFormatter());
            logger = Logger.getLogger("test");
            logger.addHandler(handler);
        } catch (IOException e) {
            e.printStackTrace();
        }
	}

	public static Message getInstance()
	{
		if (instancs == null)
		{
			instancs = new Message();
		}
		return instancs;
	}

	/**
	 * Show an error message on the system console (calls System.out.println()).
	 * Does not check showMessages flag.
	 * 
	 * @param text
	 */
	public void err(String text)
	{
		if (Config.showMessages)
		{
			logger.log(Level.WARNING, text);
		}
	}

	/**
	 * Show a debug message on the system console (calls System.out.println()).
	 * If showMessages flag is false, does nothing.
	 * 
	 * @param text
	 */
	public void msg(String text)
	{
		if (Config.showMessages)
		{
			logger.log(Level.INFO, text);
		}
	}
}
